##
## Monument by ViSa, this file has been edited by Keldath, TAfirehawk Mrgenie and Rockinroger. we thank GIR 1000times for supplying his mod to us
## vielen dank an die Hansastadt im Norden
##

from CvPythonExtensions import *
import CvUtil

import CvEventManager
import Popup as PyPopup
import PyHelpers
import CvConfigParser
import Monument

Monument = Monument.Monument()


gc = CyGlobalContext()

PyPlayer = PyHelpers.PyPlayer
PyGame = PyHelpers.PyGame()
PyInfo = PyHelpers.PyInfo

# define war between all players, also AI
g_always_WAR = False

# National Special forces training centre
g_trainingNSFTCEnabled = False

# city guard things
g_setCityGuardEnabled = False

# crusade wonder?
g_setCrusadeWonderEnabled = False

def loadConfigurationData():        
	global g_setCityGuardEnabled
	global g_setCrusadeWonderEnabled
	global g_always_WAR
	global g_trainingNSFTCEnabled
	
	# loads the ViSa Component Control ini file
	config = CvConfigParser.CvConfigParser("ViSa-Component-Control.ini")

	# If we actually were able to open the "ViSa-Component-Control.ini" file then read in the values.
	# otherwise we'll keep the default values that were set at the top of this file.
	if(config != None):
		g_always_WAR = config.getboolean(               "ViSa Component Control", "GIR Always War",                    False)
		g_trainingNSFTCEnabled = config.getboolean(     "ViSa Component Control", "GIR Training NSFTC",                False)
		g_setCityGuardEnabled = config.getboolean(      "ViSa Component Control", "GIR City Guard allowed",            False)
		g_setCrusadeWonderEnabled = config.getboolean(  "ViSa Component Control", "GIR Crusade Wonder allowed",        False)

# globals
###############################################################################################################################################
###############################################################################################################################################

class ViSaMonumentEventManager:
	def __init__(self, eventManager):

		eventManager.addEventHandler("BeginGameTurn", self.onBeginGameTurn)
		eventManager.addEventHandler("BeginPlayerTurn", self.onBeginPlayerTurn)
		eventManager.addEventHandler("improvementBuilt", self.onImprovementBuilt)
		eventManager.addEventHandler("buildingBuilt", self.onBuildingBuilt)
		eventManager.addEventHandler("unitBuilt", self.onUnitBuilt)
		
		eventManager.addEventHandler("GameStart", self.onGameStart)
		eventManager.addEventHandler("OnLoad", self.onGameStart)
		
		loadConfigurationData()

	def onGameStart(self, argsList):
		loadConfigurationData()		

	def onBeginGameTurn(self, argsList):

		iGameTurn = argsList[0]
		
		if ( g_trainingNSFTCEnabled == True ):
			Monument.NSFTCFreeExperience( iGameTurn )
		if ( g_always_WAR == True ):
			Monument.alWaysWar()

	def onBeginPlayerTurn(self, argsList):

		if ( g_setCrusadeWonderEnabled == True ):
			Monument.CrusadeWonder( argsList )

	def onImprovementBuilt(self, argsList):

		Monument.holidayResort( argsList )
		Monument.nationalParcImprovement( argsList )
		Monument.tempel(argsList )

	def onBuildingBuilt(self, argsList):

		Monument.amphitheater( argsList )
		Monument.hippodrome( argsList )
		Monument.romanRoads( argsList )
		Monument.nationalTravelAgency( argsList )
		Monument.KGBtraining( argsList )
		Monument.windFarm( argsList )
		Monument.nationalParcBuilding( argsList )
		Monument.leonardoWonderBuilding( argsList )
		Monument.cityGuardTraining( argsList )
		Monument.tallestBuilding( argsList )
		Monument.artOfArtillery( argsList )

		
		if ( g_trainingNSFTCEnabled == True ):
			Monument.NSFTCtraining( argsList )
		if ( g_setCrusadeWonderEnabled == True ):
			Monument.CrusadeWonderBuilding( argsList )

	def onUnitBuilt(self, argsList):
		'Unit Completed'

		Monument.sphinxFreePromotion( argsList )
		Monument.stablesFreePromotion( argsList )
		Monument.musketFactoryFreePromotion( argsList )
		Monument.KGBfreeSpyPromotion( argsList )
		Monument.cityCastleImprovementFreePaladin( argsList )
		
		if ( g_setCityGuardEnabled == True ):
			Monument.cityGuardFreePromotion( argsList )
			Monument.goldenAgeCityGuardGimmick( argsList )


